<template>
  <div class="about">
    <h1>This is an about page</h1>
  </div>
</template>

<script>
import {request} from '../network/request'
export default {
  name:"About",
  data() {
    return {
      
    }
  },
  methods: {

          //不传递参数，默认get方式
    getMultidata(){
      this.axios({
        //请求路径
        url:'http://123.207.32.32:8000/home/multidata',

        // 请求方式：get，post
        method:'get'
      }).then((response) => {
            // console.log(response.data)
})
    },
  //async--awai
   async agetMultidata(){
      let res=await this.axios({url:'http://123.207.32.32:8000/home/multidata'})
      console.log(res.data.data)
    },

//传递参数，可以?参数名=参数值
    getHomedata(){
      this.axios({
        url:'http://123.207.32.32:8000/home/data?type=sell&page=1'
      }).then(res=>{
        // console.log(res.data)
      })
    },

    //传递参数,params对象
    getHomedata2(){
      this.axios({
        url:'http://123.207.32.32:8000/home/data',

        // 注意，参数传递，get用params，post用data
        params:{
          type:'sell',
          page:1
        }
      }).then(res=>{
        // console.log(res.data)
      })
    },

//返回一个promise供并发请求使用
    getMultidata1(){
      return this.axios({
        url:'http://123.207.32.32:8000/home/multidata'
      })
    },
    //返回一个promise供并发请求使用
    getHomedata3(){
      return this.axios({
        url:'http://123.207.32.32:8000/home/data?type=sell&page=1'
      })
    },

    //并发请求
    getalldatas(){
      this.axios.all([this.getMultidata1(),this.getHomedata3()]).then(
        this.axios.spread((res1, res2)=>{
          console.log(res1.data)
          console.log(res2.data)
        })
        // res=>{
        //   console.log(res)
        // }
      )
    },

    //通过自己封装的request来发送请求
    async getrequestdata(){
      let res=await request({
        url:'home/multidata'
      })
      console.log(res.data)
    }
  },
  mounted() {
    
  },
  created() {
    // this.getMultidata()
    // this.getHomedata2()
    // this.getalldatas()

    // this.agetMultidata()
    this.getrequestdata()
  },
}
</script>